package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Shangjiatuangou;
import com.ruoyi.system.service.IShangjiatuangouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家团购活动Controller
 * 
 * @author ruoyi
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/system/shangjiatuangou")
public class ShangjiatuangouController extends BaseController
{
    @Autowired
    private IShangjiatuangouService shangjiatuangouService;

    /**
     * 查询商家团购活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:shangjiatuangou:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shangjiatuangou shangjiatuangou)
    {
        startPage();
        List<Shangjiatuangou> list = shangjiatuangouService.selectxiangxi(shangjiatuangou);
        // List<Shangjiatuangou> list = shangjiatuangouService.selectShangjiatuangouList(shangjiatuangou);
        return getDataTable(list);
    }

    /**
     * 导出商家团购活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:shangjiatuangou:export')")
    @Log(title = "商家团购活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shangjiatuangou shangjiatuangou)
    {
        List<Shangjiatuangou> list = shangjiatuangouService.selectShangjiatuangouList(shangjiatuangou);
        ExcelUtil<Shangjiatuangou> util = new ExcelUtil<Shangjiatuangou>(Shangjiatuangou.class);
        util.exportExcel(response, list, "商家团购活动数据");
    }

    /**
     * 获取商家团购活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shangjiatuangou:query')")
    @GetMapping(value = "/{sjtgId}")
    public AjaxResult getInfo(@PathVariable("sjtgId") Long sjtgId)
    {
        return success(shangjiatuangouService.selectShangjiatuangouBySjtgId(sjtgId));
    }

    /**
     * 新增商家团购活动
     */
    @PreAuthorize("@ss.hasPermi('system:shangjiatuangou:add')")
    @Log(title = "商家团购活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shangjiatuangou shangjiatuangou)
    {
        return toAjax(shangjiatuangouService.insertShangjiatuangou(shangjiatuangou));
    }

    /**
     * 修改商家团购活动
     */
    @PreAuthorize("@ss.hasPermi('system:shangjiatuangou:edit')")
    @Log(title = "商家团购活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shangjiatuangou shangjiatuangou)
    {
        return toAjax(shangjiatuangouService.updateShangjiatuangou(shangjiatuangou));
    }

    /**
     * 删除商家团购活动
     */
    @PreAuthorize("@ss.hasPermi('system:shangjiatuangou:remove')")
    @Log(title = "商家团购活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sjtgIds}")
    public AjaxResult remove(@PathVariable Long[] sjtgIds)
    {
        return toAjax(shangjiatuangouService.deleteShangjiatuangouBySjtgIds(sjtgIds));
    }
}
